package com.solo.system.web;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.solo.common.core.global.R;
import com.solo.common.logger.annotation.Logger;
import com.solo.common.logger.enums.LoggerType;
import com.solo.system.model.user.req.AssignPostReq;
import com.solo.system.model.user.resp.UserPostResp;
import com.solo.system.service.SysUserPostService;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 用户岗位关联控制器
 * @author 十一
 * @since 2024-10-16 17:18
 * 人生若只如初见，何事秋风悲画扇
 **/
@RestController
@AllArgsConstructor
@RequestMapping("/system/user-post")
public class SysUserPostController {

    private final SysUserPostService sysUserPostService;

    @GetMapping("/query/{userId}")
    @SaCheckPermission("system-user-assign-post")
    public R<UserPostResp> queryUserPost(@PathVariable Long userId) {
        return R.success(sysUserPostService.queryUserPost(userId));
    }

    @PutMapping("/assign-post")
    @SaCheckPermission("system-user-assign-post")
    @Logger(value = "分配岗位", type = LoggerType.UPDATE)
    public R<Boolean> assignPost(@Valid @RequestBody AssignPostReq req) {
        return R.success(sysUserPostService.assignPost(req));
    }

}
